<?php 
static $is_first = true;
if ($is_first) {
    echo '<script type="text/javascript" src="' .(tos_cdn_url('js/calendar.js')) . '"></script>';
?>
<script type="text/javascript">
    var calendar = new z.Calendar();
    function set_datetime(target) {
        var offset = z.getAbsOffset(target);
        calendar.setPos(offset.left + 5, offset.top + 20);
        calendar.show(target.value);
        calendar.submit = function () {
            target.value = z.parseTime(this.selectedDay);
            var hidden = z.s('hidden_' + target.id);
            hidden.value = Math.ceil(this.selectedDay.getTime() / 1000);
            hidden.changed = true;
            //knm.set(target.name, Math.ceil(this.selectedDay.getTime() / 1000));
            this.hide();
        };
    }
    function hide_datetime(e) {
        calendar.autoHide(e);
    }
</script>
<?php 
    $is_first = false;
}
$element_name = $this->get_data('element_name');
$element_id = 'calendar_' . time() . rand();
$hidden_id = 'hidden_' . $element_id;
?>
<input id="<?php echo $element_id; ?>" class="text" type="text" value="" />
<input name="<?php echo $element_name;?>" id="<?php echo $hidden_id;?>" type="hidden" value="" />
<script type="text/javascript">
z.s('<?php echo $element_id;?>').onclick = function () {
    set_datetime(this);
};
z.s('<?php echo $element_id;?>').onmouseout = function(e) {
    hide_datetime(e);
};
<?php if ($this->get_data('element_value')):?>
z.s('<?php echo $element_id;?>').value = z.parseTime(new Date(<?php $this->write('element_value');?> * 1000));
<?php endif;?>
</script>